package com.imay.live.view.custom;

import android.content.Context;
import android.os.Build;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.annotation.StyleRes;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;

import com.imay.live.R;

/**
 * Created by jeaman on 2017/9/27.
 */

public class DataLoadStatusView extends FrameLayout {
    private View mLoadingView;
    private View mEmptyView;
    private View mErrorView;

    public DataLoadStatusView(@NonNull Context context) {
        super(context);
        init(context);
    }

    public DataLoadStatusView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public DataLoadStatusView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public DataLoadStatusView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    private void init(Context context) {
        inflate(context, R.layout.view_data_load_status, this);
        mLoadingView = findViewById(R.id.data_load_status_ll_loading);
        mEmptyView = findViewById(R.id.data_load_status_ll_empty);
        mErrorView = findViewById(R.id.data_load_status_ll_error);
    }

    public void showLoading() {
        mLoadingView.setVisibility(VISIBLE);
        mEmptyView.setVisibility(GONE);
        mErrorView.setVisibility(GONE);
    }

    public void showEmpty() {
        mLoadingView.setVisibility(GONE);
        mEmptyView.setVisibility(VISIBLE);
        mErrorView.setVisibility(GONE);
    }

    public void showError() {
        mLoadingView.setVisibility(GONE);
        mEmptyView.setVisibility(GONE);
        mErrorView.setVisibility(VISIBLE);
    }
}
